{{include file="Manage/header.html"}}
<body class="regi_body">
	<div class="regi_header">
		<a href="javascript:">培育计划申报</a>
	</div>
	<div class="register">
		<div class="bule_bg">
			<div>用户注册</div>
		</div>
		<form action="index.php?app=Login" name="myform" method="post" class="ajaxSubmit" onsubmit="return false">
			<div class="content">
				<table>
					<tr>
						<td>姓名</td>
						<td><input type="text" name="username" tab="username"></td>
						<td class="info">请填写真实姓名</td>
					</tr>
					<tr>
						<td>性别</td>
						<td>
							<input type="radio"  id="radio1"  name="sex" value="0" checked/>
							<label for="radio1">男</label>

							<input type="radio"  id="radio2"  name="sex" value="1" />
							<label for="radio2">女</label>
						</td>
					</tr>
					<tr>
						<td>身份</td>
						<td>
							<input type="radio"  id="radio3"  name="type" value="0"/>
							<label for="radio3">老师</label>

							<input type="radio"  id="radio4"  name="type" value="1" checked/>
							<label for="radio4">学生</label>
						</td>
					</tr>
					<tr>
						<td>所在院系</td>
						<td>
							<select name="college" id="change_college">
								<option value="" selected="true">请选择所在院系...</option>
								{{if $result}}
									{{foreach from=$result item=val key=key}}
										<option value="{{$val.id}}">{{$val.title}}</option>
									{{/foreach}}
								{{/if}}
							</select>
						</td>
						<td>请选择所在院系</td>
					</tr>
					<tr>
						<td>专业</td>
						<td>
							<select name="class" id="change_class">
								<option value="">请选择专业...</option>
							</select>
						</td>
						<td>请选择专业</td>
					</tr>
					<tr>
						<td>手机号</td>
						<td><input type="text" name="number" tab="number" id="number"></td>
						<td class="info">请填写常用手机号码</td>
					</tr>
					<tr class="get_code">
						<td>验证码</td>
						<td>
							<input type="text" name="code" id="ver">
							<button onclick="test();">获取验证码</button>
						</td>
					</tr>
					<tr>
						<td>邮箱</td>
						<td><input type="text" name="email" tab="email"></td>
						<td class="info">请填写安全邮箱</td>
					</tr>
					<tr>
						<td>密码</td>
						<td><input type="password" name="password" tab="password"></td>
						<td class="info">密码由6-20位的英文字母、数字和特殊符号组成</td>
					</tr>
					<tr>
						<td>确认密码</td>
						<td><input type="password" name="password2" tab="password2"></td>
						<td class="info">请再次填写一遍密码，以辅助检测密码输入是否正确</td>
					</tr>
				</table>
				<button onclick="login();">注册</button>
				<div class="go_login"><a href="index.php?app=Login&act=index">已有账号？去登录</a></div>
			</div>
		</form>
	</div>
	<script>

		//所有验证
		$("input").blur(function(){//blur為失去焦點時觸發，用來验证输入信息，就是鼠标移开点击输入框就马上进行验证
			verify(this);
		});

			//验证
		var verify = function(obj){
			var tab = $(obj).attr('tab');//获取标志
			var val = $(obj).val();
			//用户名
			if(tab == 'username' && val){admin
				var res = /[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*/.test(val);
				html(obj,res,'真实姓名格式错误！');
			}
			//手机验证
			if(tab == 'number' && val){
				var res = /^1[3-9]\d{9}$/.test(val);
				html(obj,res,'手机号格式错误！');
			}
			//邮箱验证
			else if(tab == 'email' && val){
				var res = /^\w+(?:[-+.']\w+)*@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*$/.test(val);
				html(obj,res,'邮箱格式错误！');
			}else if(tab == 'password' && val){
				var res = /^[^\u4e00-\u9fa5\s]{6,20}$/.test(val);
				html(obj,res,'密码至少为6位！');
			}else if(tab == 's_password' && val){
				var val2 = $("input[name='password']").val();
				res = (val == val2) ? true : false;
				html(obj,res,'两次密码输入不一致！');
			}
		}

		//正则检测
		var html = function(obj,res,val){
			(res) ? $(obj).parent().parent().find(".info").removeClass("info_w").html("<p class='home'><svg  class='icon' aria-hidden='true'><use xlink:href='#icon-tongguo'></use></svg></p>") : $(obj).parent().parent().find(".info").addClass("info_w").html("<span>"+val+"</span>");
		}

		//注册验证
		function login(){
		    var sms = getCookie("sms");
		    var code = $("#ver").val();
		    if(sms == code && sms != ''){
		    	var params = $("form").serialize();
			    $.post('{{"index.php?app=Login&register_code"|URL}}',params,function(result){
			        if(result.statusCode == '200'){
			        	ui.success(result.message);
			        	setTimeout(function(){
							var url = "{{$smarty.const.__PROJECT__}}Login/index"; 
							document.location.href = url;//登录后跳转页面
						},1000);
			        }else if(result.statusCode == '300'){
			        	$("input[name='"+result.message.name+"']").parent().parent().find(".info").addClass("info_w").html(result.message.message);
			        }
			    },'json');
			}else if(code == ''){
				ui.error('请先获取并填写验证码！');
				return false;
			}else{
				ui.error('验证码填写错误！');
				return false;
			}
		}

		//院系改变
		$("#change_college").change(function(){
			var id = $(this).val();
			$.get('{{"index.php?app=Login&act=getclass"}}',{'id':id},function(result){
				if(result.statusCode == '200'){
					$("#change_class").html(result.message).trigger("chosen:updated");
				}
			},'json');
			if(id !='')
				$(this).parent().next().html("<svg height='20px' width='20px' aria-hidden='true'><use xlink:href='#icon-tongguo'></use></svg>");
			else
				$(this).parent().next().html('请选择院系').css('color','#E9686B');
		})

		//专业改变
		$("#change_class").change(function(){
			var id = $(this).val();
			if(id !='')
				$(this).parent().next().html("<svg height='20px' width='20px' aria-hidden='true'><use xlink:href='#icon-tongguo'></use></svg>");
			else
				$(this).parent().next().html('请选择院系').css('color','#E9686B');
		})

	</script>
{{include file="Manage/footer.html"}}